<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "good".
 *
 * @property int $id
 * @property string $name 名字
 * @property string $desc 货物描述
 * @property string $image 图片
 */
class Good extends \yii\db\ActiveRecord
{
    const SCENARIO_UPDATE = 'update';
    const SCENARIO_UPLOAD = 'upload';
    const SCENARIO_CREATE = 'create';

    public $file;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'good';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['desc', 'image'], 'string'],
            [['file'],'file'],
            [['file'],'safe'],
            [['name'], 'string', 'max' => 20],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'desc' => 'Desc',
            'image' => 'Image',
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_UPDATE] = ['name','desc'];
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        $scenarios[self::SCENARIO_CREATE] = ['name', 'file'];
        return $scenarios;
    }
}
